<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath %>" />
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<link rel="stylesheet" href="plugins/layui/css/layui.css" media="all" />
<link rel="stylesheet" href="css/global.css" media="all" />

</head>
<body>
	<div class="admin-main">

		<blockquote class="layui-elem-quote"></blockquote>
		<fieldset class="layui-elem-field">
			<legend>员工信息</legend>
			<input type="hidden" id="infoid" value="${currentuser.infoid }">
			<div id="info" style="width: 60%; margin: 0 auto;"></div>
		</fieldset>

	</div>
	<!--模板-->
	<script type="text/html" id="tpl">
			<blockquote class="layui-elem-quote">
				{{ d._obj.xm}}的个人信息
				<a href="javascript:;" class="layui-btn layui-btn" id="edit">
					<i class="layui-icon">&#xe608;</i> 修改
				</a>
			</blockquote>
<fieldset class="layui-elem-field">
				<legend>员工信息</legend>
				<input type="hidden" id="infoid" value ="${currentuser.infoid }">
				<div id="info" style=" width: 60%; margin: 0 auto;">
		<table class="layui-table" lay-even="" lay-skin="line">
  <colgroup>
    <col width="50">
    <col width="100">
	<col width="250">
    <col>
  </colgroup>
  <thead>
  </thead>
  <tbody>
	 <tr>
      <td>员工编码  	<a href="javascript:;" data-name='{{ JSON.stringify(d._obj) }}' data-opt="edit" class="layui-hide"></a></td>
      <td>{{ d._obj.ygbm}}</td>
	  <td rowspan = 4 ><img src="{{ d._obj.zp}}" class="layui-circle" style="width: 15em; height: 15em;"></td>
    </tr>
    <tr>
      <td>姓名</td>
      <td>{{ d._obj.xm}}</td>
    </tr>
    <tr>
      <td>性别</td>
      <td>{{ d._obj.xb}}</td>
    </tr>
   <tr>
      <td>年龄</td>
      <td>{{ goage(d._obj.sfzh)}}</td>
    </tr>
	<tr>
      <td>名族</td>
      <td colspan = 2>{{ d._obj.mz}}</td>
    </tr>
    <tr>
      <td>籍贯</td>
      <td colspan = 2 >{{ d._obj.jg}}</td>
    </tr>
	<tr>
      <td>政治面貌</td>
      <td colspan = 2 >{{ d._obj.zzmm}}</td>
    </tr>
    <tr>
      <td>学历</td>
      <td colspan = 2>{{ d._obj.xl}}</td>
    </tr>
	<tr>
      <td>学位</td>
      <td colspan = 2>{{ d._obj.xw}}</td>
    </tr>
	<tr>
      <td>专业</td>
      <td colspan = 2>{{ d._obj.zy}}</td>
    </tr>
	<tr>
      <td>出生日期</td>
      <td colspan = 2>{{ d._obj.csrq}}</td>
    </tr>

 	<tr>
      <td>身份证号</td>
      <td colspan = 2>{{ d._obj.sfzh}}</td>
    </tr>
 	<tr>
      <td>婚姻情况</td>
      <td colspan = 2>{{ d._obj.hyzk}}</td>
    </tr>
	 <tr>
      <td>入职日期</td>
      <td colspan = 2>{{ d._obj.rzrq}}</td>
    </tr>
	 <tr>
      <td>工龄</td>
      <td colspan = 2>{{ d._obj.gl}}</td>
    </tr>
 <tr>
      <td>所在项目</td>
      <td colspan = 2>{{ d._obj.xmmc}}</td>
    </tr>
 <tr>
      <td>所在部门</td>
      <td colspan = 2>{{ d._obj.szbm}}</td>
    </tr>
 <tr>
      <td>岗位名称</td>
      <td colspan = 2>{{ d._obj.gwmc}}</td>
    </tr>
 <tr>
      <td>用工性质</td>
      <td colspan = 2>{{ d._obj.ygxz}}</td>
    </tr>
 <tr>
      <td>驻场单位</td>
      <td colspan = 2>{{ d._obj.zcdw}}</td>
    </tr> <tr>
      <td>联系电话</td>
      <td colspan = 2>{{ d._obj.lxdh}}</td>
    </tr>

  </tbody>
</table> 
</div>
			</fieldset>
		</script>
	<script type="text/javascript" src="plugins/layui/layui.js"></script>
	<script>
		//身份证号算年龄 
        function goage(n){
        	var a = new Date().getFullYear();
        	var b =parseInt(n.substr(6,4));
        	return a-b;
        }
			layui.use(['laytpl','form','layer','upload'], function() {
				var $ = layui.jquery,
				layerTips = parent.layer === undefined ? layui.layer : parent.layer, //获取父窗口的layer对象
				layer = layui.layer, //获取当前窗口的layer对象
				form = layui.form(),
				laytpl = layui.laytpl;

				//全局的AJAX访问，处理AJAX清求时SESSION超时
				$.ajaxSetup({
				    contentType:"application/x-www-form-urlencoded;charset=utf-8",
				    complete:function(XMLHttpRequest,textStatus){
				          //通过XMLHttpRequest取得响应头，sessionstatus           
				          var sessionstatus=XMLHttpRequest.getResponseHeader("sessionstatus"); 
				          loginUrl = XMLHttpRequest.getResponseHeader("location"); 
				          if(sessionstatus=='00004'){
				               //这里怎么处理在你，这里跳转的登录页面
				        	 // if( window.top != window.self ){
				  				window.top.location = loginUrl;
				  			//}
				       }
				    }
				});
				
				//第三步：渲染模版
		
				var getTpl = tpl.innerHTML;
		        $.ajax({
					type: 'post',
					url:  'user/finduser',
					async: false,
					data: {id: $('#infoid').val()},
					dataType: 'json',
					success: function(result, status, xhr) {
						if(result.flag){
							laytpl(getTpl).render(result, function(html){
								  $(".admin-main").html( html);
								});
							}
						else{layer.msg(result.msg);}
						}
				});

				$('#edit').on('click', function(){

					loadUserform($('a[data-opt=edit]').data('name'));
					});

				//********************************
	             var loadUserform = function (item){
					$.get('temp/edit-user.html', null, function(form) {
							addBoxIndex = layer.open({
								type: 1,
								title: '修改表单',
								content: form,
								btn: ['保存', '取消'],
								shade: false,
								offset: ['100px', '30%'],
								area: ['600px', '400px'],
								zIndex: 19950924,
								maxmin: true,
								yes: function(index) {
									//触发表单的提交事件
									//设置提交地址
									$('form.layui-form').find('button[lay-filter=edit]').click();
								},
								full: function(elem) {
									var win = window.top === window.self ? window : parent.window;
									$(win).on('resize', function() {
										var $this = $(this);
										elem.width($this.width()).height($this.height()).css({
											top: 0,
											left: 0
										});
										elem.children('div.layui-layer-content').height($this.height() - 95);
									});
								},
								success: function(layero, index) {
									//弹出窗口成功后渲染表单
								   doDectAjax();
									var a,b;
									a = $("select[name='szbmid']");
									b =	$("select[name='gwid']");
									
									var o_data = {level:"B", url: 'organiz/findbylevl', pid: 0};
									addorganiz(o_data, a);
									o_data.level = "C";
									addorganiz(o_data, b);

									

									//给表单赋值
									/**********/
									$("input[name='gid']").val(item.gid);
									$("input[name='infoid']").val(item.infoid);
									//$("input[name='loginname']").val(item.loginname);
									//$("input[name='password']").addClass('layui-unselect');
									$("input[name='ygbm']").val(item.ygbm);
									$("input[name='xm']").val(item.xm);
									$(":radio[name='xb'][value='"+item.xb+"']").prop("checked", "checked");
									//$("input[name='mz']").val(item.mz);
									$("input[name='jg']").val(item.jg);
									$("input[name='gage']").val(item.gage);
									$("input[name='sfzh']").val(item.sfzh);
									$("input[name='zcdw']").val(item.zcdw);
									$("input[name='zy']").val(item.zy);
									//$("input[name='xw']").val(item.xw);
								//	$("input[name='xl']").val(item.xl);
									$("input[name='zc']").val(item.zc);
								//	$("input[name='zzmm']").val(item.zzmm);
									$(":radio[name='hyzk'][value='"+item.hyzk+"']").prop("checked", "checked");
									$("input[name='rzrq']").val(item.rzrq);

									$("select[name='szbmid']").val(item.szbmid);
									$("select[name='gwid']").val(item.gwid);
									
									$("select[name='gwlx']").val(item.gwlx);
									$("select[name='ygxz']").val(item.ygxz);
									$("select[name='xmmc']").val(item.xmmc);
									$("select[name='mz']").val(item.mz);
									$("select[name='xl']").val(item.xl);
									$("select[name='xw']").val(item.xw);
									$("select[name='zzmm']").val(item.zzmm);
									
									$("input[name='lxdh']").val(item.lxdh);
									$("#LAY_demo_upload").attr('src', item.zp);
									$("#zp").val(item.zp);
									
									
									/************/	
									var form = layui.form();
									form.render();
									layui.upload({
									    url: '_upload'
									    ,elem: '#test' //指定原始元素，默认直接查找class="layui-upload-file"
									    ,method: 'post' //上传接口的http类型
									    ,success: function(res){
										    if(res.isSuccess){
										  $('#zp').val(res.url);   
									      LAY_demo_upload.src = res.url;
										    }
										}
									 });
									//部门级联操作
									form.on('select(depart)',function(data){
										o_data.url = 'organiz/findbypid'
										o_data.pid = data.value;
										addorganiz(o_data, b);
										form.render("select");
									});
									
									form.on('submit(edit)', function(data) {
									   delete data.field.file;
										$.ajax({
											type: 'post',
											url:  'user/adduserinfochange',
											data: data.field,
											dataType: 'json',
											success: function(result, status, xhr) {
												if(result.flag){
													layer.closeAll();
													location.reload(); //刷新
													}
												}
										});
										
										return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。									
									});
									//console.log(layero, index);
								},
								end: function() {
									addBoxIndex = -1;
								}
							});
						});
					}
	         	//加载字典项
					var doDectAjax=function(){
						$.ajax({type: 'get',url:  'selectdect',
							//data: data.field,
							async: false,dataType: 'json',success: function(result, status, xhr) {
								if(result.flag){
										$(result.list).each(function(i,item){
												switch (item.dtype){
												case "RIGHT" :
													$("select[name='right']").append("<option value='" +item.dictid+"'>"+item.dname+"</option>");
													break;
											 	case "SEX" :
											 		 var s = item.temp == 'true' ? 'checked':'';
													$("#sex").append('<input type="radio" name="xb" value="'+item.dname+'" title="'+item.dname+'" '+s+ ' >');
													//$("select[name='xb']").append("<option value='"+item.dname+"'>"+item.dname+"</option>");
													break;
												case "MARRY" :
												    var s = item.temp == 'true' ? 'checked':'';
													$("#hyzk").append('<input type="radio" name="hyzk" value="'+item.dname+'" title="'+item.dname+'" '+s+' >');
													break; 
												case "NA" :
													$("select[name='ygxz']").append("<option value='"+item.dname+"'>"+item.dname+"</option>");
													break;
												case "POST" :
													$("select[name='gwlx']").append("<option value='" +item.dname+"'>"+item.dname+"</option>");
													break;
												case "PRO" :
													$("select[name='xmmc']").append("<option value='" +item.dname+"'>"+item.dname+"</option>");
													break;
												case "EDU" :
													$("select[name='xl']").append("<option value='" +item.dname+"'>"+item.dname+"</option>");
													break;
												case "NATION" :
													$("select[name='mz']").append("<option value='" +item.dname+"'>"+item.dname+"</option>");
													break; 
												case "POL" :
													$("select[name='zzmm']").append("<option value='"+item.dname+"'>"+item.dname+"</option>");
													break;
												case "DEGREE" :
													$("select[name='xw']").append("<option value='"+item.dname+"'>"+item.dname+"</option>");
													break;
												default:
													break;
													}
											});
									}
								}
						});
						}
					// 部门职位
					var addorganiz = function(o_data, o){
						//加载前清空select
						$(o).empty();
						$.ajax({
							type: 'get',
							url:  o_data.url,
							data: o_data,
							async: false,
							dataType: 'json',
							success: function(result, status, xhr) {
								if(result.flag){
									 $(o).append("<option value=''></option>");
									$(result.list).each(function(i,item){
								      $(o).append("<option value='" +item.bmbh+"'>"+item.oname+"</option>");
									});
									}
								}
						});
					}
			
			});
		</script>
</body>
</body>

</html>